---
import NoteCard from "@components/NoteCard.astro";
import BaseLayout from "@layouts/BaseLayout.astro";

import { getAllNotes, mdTimeFilter } from "@utils/astroUtil";

const notes = await Promise.all((await getAllNotes()).filter(mdTimeFilter)
                .sort((noteBef, noteAft) => noteAft.data.pubDate.valueOf() - noteBef.data.pubDate.valueOf())
                .map(async (note) => {
                    const { Content } = await note.render();
                    return {
                        Content,
                        frontmatter: note.data,
                        slug: note.slug,
                    }
                }));
---

<BaseLayout title="随手一记">
    <section class="notes-wrapper">
        {(
            notes.map(({Content, frontmatter, slug}) => {
                return (
                    <NoteCard frontmatter={ frontmatter } slug={ slug }>
                        <Content />
                    </NoteCard>
                )
            })
        )}
    </section>
</BaseLayout>


<style lang="scss">
.notes-wrapper {
    padding-top: 40px;
}
</style>
